//
//  DHTabBarController.m
//  DHWeibo
//
//  Created by donghai on 15/12/6.
//  Copyright © 2015年 东海. All rights reserved.
//

#import "DHTabBarController.h"
#import "DHDiscoverViewController.h"
#import "DHHomeViewController.h"
#import "DHMessageViewController.h"
#import "DHMeViewController.h"

@interface DHTabBarController ()

@end

@implementation DHTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加子控制器
    //添加首页
    DHHomeViewController *homeVc = [[DHHomeViewController alloc] init];
    [self addChildVCWith:homeVc title:@"首页" nmlImgName:@"tabbar_home" selImgName:@"tabbar_home_selected"];
    //添加信息
    DHMessageViewController *msgVc = [[DHMessageViewController alloc] init];
    [self addChildVCWith:msgVc title:@"信息" nmlImgName:@"tabbar_message_center" selImgName:
     @"tabbar_message_center_selected"];
    
    //添加发现
    DHDiscoverViewController *discVc = [[DHDiscoverViewController alloc] init];
    [self addChildVCWith:discVc title:@"发现" nmlImgName:@"tabbar_discover" selImgName:@"tabbar_discover_selected"];
    
    //添加我
    DHMeViewController *meVc = [[DHMeViewController alloc] init];
    [self addChildVCWith:meVc title:@"我" nmlImgName:@"tabbar_profile" selImgName:@"tabbar_profile_selected"];
}

/**
 *  添加tabbar子控制器
 *
 *  @param vc         tabbar的子控制器(导航控制器)的子控制器
 *  @param title      tabbarBtn标题
 *  @param nmlImgName tabbarBtn 正常图片
 *  @param selImgName tabbarBtn 选中图片
 */
-(void)addChildVCWith:(UIViewController *)vc title: (NSString *)title nmlImgName:(NSString *)nmlImgName selImgName:(NSString *)selImgName {
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    //设置标题
    nav.tabBarItem.title = title;
    //设置普通状态图片
    nav.tabBarItem.image = [UIImage imageNamed:nmlImgName];
    //设置高度
    UIImage *selImg = [UIImage imageNamed:selImgName];
    selImg = [selImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nav.tabBarItem.selectedImage = selImg;
}

@end
